const {
  add,
  find,
  update,
} = require("../model/timeArrowModel");

//获取
const getTimeData = async (req, res, next) => {
  let { id, date } = req.body;
  const result = await find(req.body);

  if (result.length || result.length === 0) {
    res.send({ httpStatus: 200, total: result.length, data: result });
  } else {
    res.send({ httpStatus: 400, msg: "查询出错" });
  }
};
//新增
const addTimeData = async (req, res, next) => {
  const { date, weather, content, id } = req.body;
  const result = await add(req.body);
  if (result) {
    res.send({ httpStatus: 200, msg: "增加成功", data: result });
  } else {
    res.send({ httpStatus: 400, msg: "增加出错" });
  }
};

//修改
const updateTimeData = async (req, res) => {
  const { _id } = req.body;
  const query = { _id };
  const updated = req.body;
  const result = await update(query, updated);
  if (result.nModified !== 0) {
    res.send({ httpStatus: 200, msg: "修改成功" });
  } else {
    res.send({ httpStatus: 400, msg: "修改出错" });
  }
};
module.exports = {
  getTimeData,
  addTimeData,
  updateTimeData,
};
